'use strict';


// 简单的选择器封装
var $$ = {
    getEle: function(id) {
        return document.getElementById(id);
    }
};

// 天地图的图层对象
var TianMap = {
    getNormal: function() {
        return L.layerGroup([L.tileLayer.chinaProvider('TianDiTu.Normal.Map', {
            maxZoom: 18,
            minZoom: 1
        }), L.tileLayer.chinaProvider('TianDiTu.Normal.Annotion', {
            maxZoom: 18,
            minZoom: 1
        })]);
    },
    getImage: function() {
        return L.layerGroup([L.tileLayer.chinaProvider('TianDiTu.Satellite.Map', {
            maxZoom: 18,
            minZoom: 1
        }), L.tileLayer.chinaProvider('TianDiTu.Satellite.Annotion', {
            maxZoom: 18,
            minZoom: 1
        })]);
    },
    getTerrain: function() {
        return L.layerGroup([L.tileLayer.chinaProvider('TianDiTu.Terrain.Map', {
            maxZoom: 18,
            minZoom: 1
        }), L.tileLayer.chinaProvider('TianDiTu.Terrain.Annotion', {
            maxZoom: 18,
            minZoom: 1
        })]);
    }
};

var CMap = function(mapId, defaultLayer, option, crs) {
    'use strict';

    var crs = crs || L.CRS.EPSG3857,
        defaultLayer = defaultLayer || TianMap.getNormal();

    var map = L.map(mapId, { // 地图
        crs: crs, // web墨卡托
        // crs: L.CRS.EPSG4326,
        doubleClickZoom: false,
        layers: [defaultLayer],
        zoomControl: false,
        attributionControl: false
    });

    this.map = map;
    this.defaultLayer = defaultLayer;

    // // 设置工具
    // this.addZoom();
    // this.addMeasure();
    // this.addCoord();
    // this.addScale();

    return this;
}

CMap.prototype = {
    getMap: function() {
        return this.map;
    },
    setCView: function(center, zoom) {
        this.map.setView(center, zoom);

        return this;
    },
    setLayers: function(base, over, option) {
        var defaultLayer = this.defaultLayer;

        var base = base || { // 切换基础图层的对象
                "地图": defaultLayer,
                "影像": TianMap.getImage(),
                "地形": TianMap.getTerrain()
            },
            over = over || {},
            option = option || {
                position: 'topright',
                collapsed: false
            };

        var layerControl = L.control.layers(base, over, option).addTo(this.map);

        for (var p in over) {
            this.map.addLayer(over[p]);
        }

        return this;
    },
    addMeasure: function() {
        if (L.control.measure !== undefined) {
            // 测距离和面积
            L.control.measure({
                position: 'topleft',
                primaryLengthUnit: 'meters',
                primaryAreaUnit: 'sqmeters',
                // activeColor: '#ABE67E',
                activeColor: '#ff0000',
                // completedColor: '#C8F2BE',
                completedColor: '#ff0000',
                localization: 'cn',
                popupOptions: { className: 'leaflet-measure-resultpopup', autoPanPadding: [10, 10] }
            }).addTo(this.map);

            return this;
        } else {
            // 没有引入插件
            throw new Error('页面没有引入相关js文件');
        }
    },
    addZoom: function() {
        // 缩放
        L.control.zoom({ zoomInTitle: '放大', zoomOutTitle: '缩小' }).addTo(this.map);

        return this;
    },
    addCoord: function() {
        // 经纬度坐标
        L.control.coordinates({
            position: "bottomleft",
            labelTemplateLat: "纬度: {y}",
            labelTemplateLng: "经度: {x}",
            enableUserInput: false
        }).addTo(this.map);

        return this;
    },
    addScale: function() {
        if (L.control.scale !== undefined) {
            L.control.scale({ imperial: false }).addTo(this.map);

            return this;
        } else {
            throw new Error('页面没有引入相关js文件');
        }
    },
    addReturn: function() {
        var map = this.map;

        if (L.easyButton !== undefined) {
            // 地图置中
            L.easyButton('<span class="fa fa-undo"></span>', function(e) {
                map.setView(e._map._lastCenter, 12);
            }, '返回').addTo(map);

            return this;
        } else {
            throw new Error('页面没有引入相关js文件');
        }

    },
    addSlider: function(callee) {
        if (L.control.slider !== undefined) {
            L.control.slider(callee, {
                position: 'topleft',
                max: 1,
                value: 1,
                step: 0.1,
                size: '100px',
                // orientation: 'vertical',
                orientation: 'horizontal',
                id: 'slider',
                title: '透明度',
                logo: 'S'
            }).addTo(this.map);

            return this;
        } else {
            throw new Error('页面没有引入相关js文件');
        }
    }
};


// 处理扇形角度的对象
var SectorAngle = {
    d2r: function(degree) {
        // 将角度转换为弧度
        return degree * (Math.PI / 180);
    },
    start: function(directAngle) {
        // 根据扇区方向角转换画扇形时的起始角度
        return -(450 - directAngle - 15);
    },
    end: function(directAngle) {
        return -(450 - directAngle + 15);
    },
    transform: function(directAngle) {
        // 图片格式的扇区旋转角度转换
        return (270 + directAngle - 15);
    },
    getRadius: function(level, option) {
        var radius = 0, // 画扇区的默认半径(px)
            cover = 300, // 基站的有效覆盖距离
            scalePx = 90, // 地图比例尺的长度(px)
            scale = {
                10: 10000,
                11: 5000,
                12: 3000,
                13: 1000,
                14: 500,
                15: 300,
                16: 200,
                17: 100,
                18: 50
            };

        if (option !== undefined && N.Util.isObject(option)) {
            radius = option.radius;
            cover = option.cover;
            scalePx = option.scalePx;
            scale = option.scale;
        }

        if (10 <= level && level <= 12) {
            radius = 16;
        } else if (13 <= level && level <= 18) {
            radius = (cover / scale[level]) * scalePx;
        }

        return radius;
    }
};

// 坐标计算类
var PointUtil = {
    /**
     * 计算地图中多个点的中心坐标
     * @param [array] points 点，示例：[{x: 100.100, y: 20.100}, {x: 100.101, y: 20.101}], x为经度，y为经度
     * @return [boolean] false OR [object] 示例：{lat: 20.102, lng: 100.102} {纬度, 经度}
     */
    getCenter: function(points) {
        if (!(points instanceof Array)) {
            throw new Error('参数类型错误 param type error');
        }

        var length = points.length;

        if (length === 0) {
            // 传递的参数（数组）长度为0
            return false;
        } else {
            var sPoints = points;

            if (N.Util.isArray(points[0])) {
                var sPoints = [];

                // 如果points[0]为数组 [100.102, 20.102], 则将其适配为{x: 100.100, y: 20.100}形式
                for (var j = 0; j < length; j++) {
                    sPoints.push({
                        x: points[j][0],
                        y: points[j][1]
                    });
                }
            } else if (N.Util.isObject(points[0]) && points[0].lat && points[0].lng) {
                // {lat: 100.102, lng: 20.102}形式
                var sPoints = [];

                for (var j = 0; j < length; j++) {
                    sPoints.push({
                        x: points[j].lng,
                        y: points[j].lat
                    });
                }
            } else if (N.Util.isObject(points[0]) && points[0].lat && points[0].lon) {
                // {lat: 20.102, lng: 100.102}形式
                var sPoints = [];

                for (var j = 0; j < length; j++) {
                    sPoints.push({
                        x: points[j].lon,
                        y: points[j].lat
                    });
                }
            }

            var maxY = sPoints[0].y,
                maxX = sPoints[0].x,
                minY = sPoints[0].y,
                minX = sPoints[0].x;

            for (var i = 1, point; point = sPoints[i]; i++) {
                // 找出最大、最小经纬度
                if (maxY < point.y) {
                    maxY = point.y;
                }
                if (maxX < point.x) {
                    maxX = point.x;
                }
                if (minY > point.y) {
                    minY = point.y;
                }
                if (minX > point.x) {
                    minX = point.x;
                }
            }

            // 返回中心点经纬度
            return { lat: (maxY + minY) / 2, lng: (maxX + minX) / 2 };
        }
    },
    /**
     * 判断某个覆盖物是否在某个多边形内
     * 
     * @param [object] marker leaflet的marker对象
     * @param [array] points 组成多边形的顶点数组，示例：[[100.100, 20.101], [100.101, 20.102], [100.102, 20.103]],
     *                单个点：point = [100.100， 20.101]，其中point[0]为经度，point[1]为纬度
     * @return [boolean]
     */
    isMarkerInPolygon: function(marker, points) {
        var x = marker.getLatLng().lat,
            y = marker.getLatLng().lng,
            length = points.length,
            inside = false;

        for (var i = 0, j = length - 1; i < length; j = i++) {
            var xi = points[i][1], // 纬度
                yi = points[i][0], // 经度
                xj = points[j][1],
                yj = points[j][0];
            intersect = ((yi > y) != (yj > y)) && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);

            if (intersect) {
                inside = !inside;
            }
        }

        return inside;
    }
};


// AjaxAdapter类：服务端数据适配器
var AjaxAdapter = {
    // 通用适配器
    common: function(data) {
        // 将后端数据适配为前端固定格式数据返回
        return {
            code: data.code, // 返回成功与否的标识码
            data: data.data, // 数据
            msg: data.msg // 信息
        };
    },
    /**
     * relay、基站等数据适配
     *
     * @param [array] data [{lng: 100.012, lat: 34.024}, ......]
     * @param [string] type 
     * @return [array] sData [{x: 100.012, y: 34.024}, ......]
     */
    points: function(data, type) {
        if (!N.Util.isArray(data)) {
            // data不是数组
            throw new Error('param type error 参数不是数组');
        }

        if ($.inArray(type, ['relay', 'ap', 'station', 'mrstation']) === -1) {
            throw new Error('param error 第二个参数不合法');
        }

        var length = data.length;

        if (length === 0) {
            // 如果data为空数组，则无需适配
            return data;
        }

        var sData = [];

        if (type === 'relay') {
            for (var i = 0; i < length; i++) {
                sData.push({
                    x: data[i].lng,
                    y: data[i].lat,
                    a: data[i].a,
                    bD: data[i].bD,
                    na: data[i].na,
                    id: data[i].id,
                    uD: data[i].uD
                });
            }
        } else if (type === 'ap') {
            for (var i = 0; i < length; i++) {
                sData.push({
                    x: data[i].lng,
                    y: data[i].lat,
                    uId: data[i].uId,
                    na: data[i].na,
                    id: data[i].id,
                });
            }
        } else if (type === 'station') {
            for (var i = 0; i < length; i++) {
                sData.push({
                    a: data[i].a,
                    id: data[i].id,
                    x: data[i].x,
                    y: data[i].y
                });
            }
        }

        return sData;
    },
    coord: function(coords, data) {
        // 坐标转换
        if (!(data instanceof Array)) {
            throw new Error('参数不对');
        }

        var sData = [],
            length = data.length;

        // var coords = CoordMap.map(q, xOffset, yOffset);

        for (var i = 0; i < length; i++) {
            sData.push({
                x: coords[data[i].x + 'x'],
                y: coords[data[i].y + 'y'],
                w: data[i].w
                // w: parseInt(data[i].w, 10)
            });
        }

        return sData;
    },
    obj2arr: function(data) {

        if (!N.Util.isObject(data)) {
            throw new Error('param type error 参数不是对象');
        }

        var arr = [];

        for (var o in data) {
            arr.push({
                column1: o,
                column2: data[o]
            });
        }

        console.log(arr);

        return arr;
    }
};


// 色带
var Color = {
    getByWeight: function(w) {
        // 归一化后的权重范围为：0 - 2
        // 默认为底色
        var red = 0,
            green = 0,
            blue = 153;

        if (w === 0) {
        } else if (0 < w && w <= 0.2) {
            // rgb(0, 0, 204) 蓝色
            blue = blue + 51;
        } else if (0.2 < w && w <= 0.4) {
            // rgb(0, 0, 255)
            blue = blue + 51 * 2;
        } else if (0.4 < w && w <= 0.6) {
            // rgb(0, 102, 255)
            green = green + 51 * 2;
            blue = blue + 51 * 2;
        } else if (0.6 < w && w <= 0.8) {
            // rgb(0, 153, 255)
            green = green + 51 * 3;
            blue = blue + 51 * 2;
        } else if (0.8 < w && w <= 1) {
            // rgb(0, 255, 255) 青色
            green = green + 51 * 5;
            blue = blue + 51 * 2;
        } else if (1 < w) {
            // 255 255 0 黄色
            red = red + 51 * 5;
            green = green + 51 * 5;
            blue = blue + 51 * (-3);
        }

        var color = 'rgb(' + red + ', ' + green + ', ' + blue + ')';

        return color;
    }
};

// canvas画散点图对象
var CanvasCoord = {
    mapCoord: function(q, xOffset, yOffset) {
        // 返回49 - 81的坐标映射对象
        var obj = {};

        for (var i = 0, j = 49; i <= 81; i++, j++) {
            obj[j + 'x'] = j + q * i + xOffset;
            obj[j + 'y'] = -(j + q * i) + yOffset;
        }

        return obj;
    },
    drawCoord: function(obj) {
        var canvas = obj.canvas,
            ctx = obj.ctx,
            grid_size = obj.grid_size, // 网格的宽和高 px
            x_lines = obj.x_lines, // 第几条网格线为x轴
            y_lines = obj.y_lines, // 第几条网格线为y轴
            x_start = obj.x_start,
            y_start = obj.y_start,
            origin = obj.origin,
            x_special = obj.x_special,
            y_special = obj.y_special;

        // canvas画布的宽和高，页面中设置的标签属性10
        var canvas_width = canvas.width,
            canvas_height = canvas.height;

        // x、y方向网格线的距离
        var num_lines_x = Math.floor(canvas_height / grid_size), // 400/40 = 10
            num_lines_y = Math.floor(canvas_width / grid_size); // 400/40 = 10


        // Draw grid lines along X-axis  画平行于x轴的网格线
        for (var i = 0; i <= num_lines_x; i++) {
            ctx.beginPath();
            ctx.lineWidth = 1;

            // 如果x轴代表
            // If line represents X-axis draw in different color
            if (i === x_lines) {
                // ctx.strokeStyle = "#000000";
                ctx.strokeStyle = "#ffffff";
                // console.log('黑色', i);
            } else {
                // ctx.strokeStyle = "#e9e9e9";
                ctx.strokeStyle = "#352a86";
                // console.log('灰色', i);
            }

            if (i === num_lines_x) {
                // 如果到了画布结束的位置，将画笔移动至x轴的最左端
                ctx.moveTo(0, grid_size * i);
                ctx.lineTo(canvas_width, grid_size * i);

                // console.log('i等于网格线条数10时画笔的位置为x=0, y=', grid_size * i);
                // console.log('此时使用lineTo方法绘制直线，终点坐标为: ', canvas_width, grid_size * i);
            } else {
                // 如果没有到结束的位置，将画笔移动至x轴
                ctx.moveTo(0, grid_size * i + 0.5);
                ctx.lineTo(canvas_width, grid_size * i + 0.5);

                // console.log('i不等于网格线条数10时画笔的位置为x=0, y=', grid_size * i + 5);
                // console.log('此时使用lineTo方法绘制直线，终点坐标为: ', canvas_width, grid_size * i + 5);
            }

            // if (i === x_special) {
            //     ctx.strokeStyle = "#ffffff";

            //     // 在指定位置画线
            //     ctx.moveTo(grid_size, grid_size * i);
            //     ctx.lineTo(canvas_width, grid_size * i);
            // }

            ctx.stroke();
        }

        // if (i === x_special) {
        ctx.strokeStyle = "#ffffff";

        // 在指定位置画线
        ctx.moveTo(grid_size, grid_size * 3);
        ctx.lineTo(canvas_width, grid_size * 3);
        ctx.stroke();
        // }

        // Draw grid lines along Y-axis  画平行于y轴的网格线
        for (i = 0; i <= num_lines_y; i++) {
            ctx.beginPath();
            ctx.lineWidth = 1;

            // If line represents X-axis draw in different color
            if (i === 1) {
                // ctx.strokeStyle = "#000000";
                ctx.strokeStyle = "#ffffff";
            } else {
                // ctx.strokeStyle = "#e9e9e9";
                ctx.strokeStyle = "#352a86";
            }

            if (i === num_lines_y) {
                ctx.moveTo(grid_size * i, 0);
                ctx.lineTo(grid_size * i, canvas_height);

                // console.log('i等于网格线条数10时画笔的位置为y=0, x=', grid_size * i);
                // console.log('此时使用lineTo方法绘制直线，终点坐标为: ', grid_size * i, canvas_height);
            } else {
                ctx.moveTo(grid_size * i + 0.5, 0);
                ctx.lineTo(grid_size * i + 0.5, canvas_height);

                // console.log('i不等于网格线条数10时画笔的位置为x=0, y=', grid_size * i);
                // console.log('此时使用lineTo方法绘制直线，终点坐标为: ', canvas_width, grid_size * i);
            }

            // if (i === y_special) {
                // ctx.strokeStyle = "#ffffff";

                // // 在指定位置画线
                // ctx.moveTo(grid_size * i, 0);
                // ctx.lineTo(grid_size * i, canvas_height - grid_size);
            // }

            ctx.stroke();
        }

        ctx.strokeStyle = "#ffffff";

        // 在指定位置画线
        ctx.moveTo(grid_size * 8, 0);
        ctx.lineTo(grid_size * 8, canvas_height - grid_size);
        ctx.stroke();

        // 保存canvas状态
        ctx.save();

        // 移动canvas的原点至左下方：即原点由(0, 0) --> (0, 400)
        // 此时画布四个角的坐标分别为：左上角: (0, 400) | 左下角: (0, 0) | 右上角: (400, 400) | 右下角: (400, 0)
        ctx.translate(40, y_lines * grid_size);


        // x轴刻度
        // Ticks marks along the positive X-axis
        // for(i = 1; i < (num_lines_y - y_lines); i++) {
        for (i = 0; i < canvas_width / grid_size; i++) {
            ctx.beginPath();
            ctx.lineWidth = 1;
            // ctx.strokeStyle = "#000000";
            ctx.fillStyle = "white";

            // Draw a tick mark 6px long (-3 to 3)
            ctx.moveTo(grid_size * i + 0.5, -3);
            ctx.lineTo(grid_size * i + 0.5, 3);
            ctx.stroke();

            // Text value at that point
            ctx.font = '9px Arial';
            ctx.textAlign = 'start';
            ctx.fillText((x_start.number * i + 4) * 10 + x_start.suffix, grid_size * i + 4, 15);
        }

        // y轴刻度
        for (i = 0; i < canvas_height; i++) {
            ctx.beginPath();
            ctx.lineWidth = 1;
            // ctx.strokeStyle = "#000000";
            ctx.fillStyle = "white";

            // Draw a tick mark 6px long (-3 to 3)
            ctx.moveTo(-3, -grid_size * i + 0.5);
            ctx.lineTo(3, -grid_size * i + 0.5);
            ctx.stroke();

            // Text value at that point
            ctx.font = '9px Arial';
            ctx.textAlign = 'start';
            ctx.fillText((y_start.number * i + 4) * 10 + y_start.suffix, -20, -grid_size * i - 3);
        }

        // ctx.restore();
    },
    drawSpecial: function(obj) {
        var canvas = obj.canvas,
            ctx = obj.ctx,
            grid_size = obj.grid_size,
            x_special = obj.x_special,
            y_special = obj.y_special,
            strokeStyle = obj.strokeStyle;

        var canvas_width = canvas.width,
            canvas_height = canvas.height;

        ctx.moveTo(0, 320);
        ctx.lineWidth = 1;
        ctx.strokeStyle = 'red';

        ctx.lineTo(400, 8 * 40);

        ctx.stroke();
    }
};


// 画图对象
var Draw = {
    imgCircle: function(obj) {
        var stage = obj.stage,
            x = obj.x,
            y = obj.y,
            event = obj.event,
            info = obj.info,
            requestData = obj.requestData,
            map = obj.map,
            img = obj.img,
            imgWidth = obj.imgWidth,
            imgHeight = obj.imgHeight,
            url = obj.url;

        // console.log(requestData);

        var $leafletGrab = $('.leaflet-grab');

        var circle = new createjs.Bitmap(img);

        circle.set({ x: x - imgWidth, y: y - imgHeight });

        // 事件处理回调函数
        var eventCallBack = function(e) {
            // 点击基站或扇区时，请求单个基站的后台数据，弹出信息
            // 这里是一个假的ajax请求。 如果不做ajax请求，popup弹出后会理解消失，原因未明
            // LayerAjax.ajax({
            //     url: url,
            //     dataType: 'json',
            //     method: 'POST',
            //     requestData: requestData,
            //     info: info,
            //     map: map
            // });
        };

        var mouseover = function(e) {
            $leafletGrab.css('cursor', 'pointer');
        };

        var mouseout = function(e) {
            $leafletGrab.css('cursor', '-webkit-grab');
            $leafletGrab.css('cursor', '-moz-grab');
            $leafletGrab.css('cursor', 'grab');
        };

        // 给图形添加事件监听器
        circle.removeEventListener(event, eventCallBack);
        circle.addEventListener(event, eventCallBack);

        // 鼠标移入事件
        circle.removeEventListener('mouseover', mouseover);
        circle.addEventListener('mouseover', mouseover);

        // 鼠标移出事件
        circle.removeEventListener('mouseover', mouseout);
        circle.addEventListener('mouseout', mouseout);

        // 将图形添加到stage
        circle.snapToPixel = true;
        stage.addChild(circle);
    },
    imgSector: function(obj) {
        var stage = obj.stage,
            x = obj.x,
            y = obj.y,
            event = obj.event,
            info = obj.info,
            requestData = obj.requestData,
            map = obj.map,
            img = obj.img,
            angle = obj.angle,
            imgWidth = obj.imgWidth,
            imgHeight = obj.imgHeight,
            url = obj.url;

        var $leafletGrab = $('.leaflet-grab');

        var sector = new createjs.Bitmap(img);

        sector.setTransform(x, y, 1, 1, angle);

        // 事件处理回调函数
        var eventCallBack = function(e) {
            // 点击基站或扇区时，请求单个基站的后台数据，弹出信息
            // LayerAjax.ajax({
            //     url: url,
            //     dataType: 'json',
            //     method: 'POST',
            //     requestData: requestData,
            //     info: info,
            //     map: map
            // });
        };

        var mouseover = function(e) {
            $leafletGrab.css('cursor', 'pointer');
        };

        var mouseout = function(e) {
            $leafletGrab.css('cursor', '-webkit-grab');
            $leafletGrab.css('cursor', '-moz-grab');
            $leafletGrab.css('cursor', 'grab');
        };

        // 给图形添加事件监听器
        sector.removeEventListener(event, eventCallBack);
        sector.addEventListener(event, eventCallBack);

        // 鼠标移入事件
        sector.removeEventListener('mouseover', mouseover);
        sector.addEventListener('mouseover', mouseover);

        // 鼠标移出事件
        sector.removeEventListener('mouseover', mouseout);
        sector.addEventListener('mouseout', mouseout);

        // 将图形添加到stage
        sector.snapToPixel = true;
        stage.addChild(sector);
    },
    sector: function(obj) {
        var stage = obj.stage,
            x = obj.x,
            y = obj.y,
            radius = obj.radius,
            start = obj.start,
            end = obj.end,
            anticlock = obj.anticlock,
            fillStyle = obj.fillStyle,
            event = obj.event,
            requestData = obj.requestData,
            requestUrl = obj.requestUrl,
            map = obj.map,
            info = obj.info,
            strokeStyle = obj.strokeStyle;

        var circle = new createjs.Shape(),
            g = circle.graphics,
            $leafletGrab = $('.leaflet-grab');

        // 事件处理回调函数
        var eventCallback = function(e) {

          $.ajax({
            url: requestUrl,
            method: 'GET',
            // data: requestData
          }).done(function(data) {
            var content = '<div class="mlayer-content">' +
            '<div>小区cgi：' + info.cgi + '</div>' +
            '<div>小区方向角：' + info.ana + '</div>' +
            '<div>小区经度：' + info.lon + '</div>' +
            '<div>小区纬度：' + info.lat + '</div>' +
            '</div>';

            L.popup()
              .setLatLng({ lat: info.lat, lon: info.lon })
              .setContent(content)
              .openOn(map);
          }).fail(function(jqxhr) {
            console.log(jqxhr);
          });
        };

        var mouseover = function(e) {
            $leafletGrab.css('cursor', 'pointer');
        };

        var mouseout = function(e) {
            $leafletGrab.css('cursor', '-webkit-grab');
            $leafletGrab.css('cursor', '-moz-grab');
            $leafletGrab.css('cursor', 'grab');
        };

        // 给图形添加事件监听器
        if (event !== undefined && $.inArray(event, ['click']) !== -1) {
            circle.removeEventListener(event, eventCallback);
            circle.addEventListener(event, eventCallback);
        }


        // 鼠标移入事件
        circle.removeEventListener('mouseover', mouseover);
        circle.addEventListener('mouseover', mouseover);

        // 鼠标移出事件
        circle.removeEventListener('mouseover', mouseout);
        circle.addEventListener('mouseout', mouseout);

        g.mt(x, y).s(strokeStyle).f(fillStyle).a(x, y, radius, SectorAngle.d2r(start), SectorAngle.d2r(end), anticlock).ef().es();
        g.mt(x, y).s(strokeStyle).f(fillStyle).a(x, y, radius, SectorAngle.d2r(end), SectorAngle.d2r(end), anticlock).ef().es();
        circle.snapToPixel = true;
        stage.addChild(circle);
    },
    rawSector: function(obj) {
        // 原生js画圆
        var ctx = obj.ctx,
            x = obj.x,
            y = obj.y,
            r = obj.r,
            start = obj.start,
            end = obj.end,
            fillStyle = obj.fillStyle;

        ctx.fillStyle = fillStyle;
        ctx.beginPath();
        ctx.moveTo(x, y);
        ctx.arc(x, y, r, start, end);
        ctx.fill();
    }
};